package com.apes.framework.plugin.soe.core.service.impl;

import com.apes.framework.plugin.soe.core.service.RuntimeService;
import com.apes.framework.plugin.soe.metadata.*;
import com.apes.framework.plugin.soe.store.database.service.SceneInstanceService;
import com.apes.framework.plugin.soe.store.database.service.SceneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 功能：运行时服务实现类
 *
 * @author xul
 * @create 2018-09-25 17:40
 */
@Component
public class RuntimeServiceImpl implements RuntimeService {

    @Autowired
    SceneService sceneService;

    @Autowired
    SceneInstanceService sceneInstanceService;

    /**
     * 创建场景实例
     *
     * @param sceneId
     */
    @Override
    public SceneInstance startSceneInstanceByKey(String sceneId) {
        Scene scene = sceneService.findById(sceneId);
        return startSceneInstance(scene);
    }

    /**
     * 创建场景实例
     *
     * @param scene
     */
    @Override
    public SceneInstance startSceneInstance(Scene scene) {
        return sceneInstanceService.createSceneInstance(scene);
    }

    /**
     * 标记场景实例已完成
     *
     * @param sceneInstance
     */
    @Override
    public void finishedSceneInstance(SceneInstance sceneInstance) {
        sceneInstanceService.finishedSceneInstance(sceneInstance);
    }

    /**
     * 挂起场景实例
     *
     * @param sceneInstanceId
     */
    @Override
    public void suspendSceneInstanceById(String sceneInstanceId) {
        sceneInstanceService.suspendSceneInstanceById(sceneInstanceId);
    }

    /**
     * 激活场景实例
     *
     * @param sceneInstanceId
     */
    @Override
    public void activateSceneInstanceById(String sceneInstanceId) {
        sceneInstanceService.activateSceneInstanceById(sceneInstanceId);
    }

    /**
     * 查的场景实例
     *
     * @param sceneInstanceId
     */
    @Override
    public SceneInstance findSceneInstance(String sceneInstanceId) {
        return sceneInstanceService.sceneInstanceService(sceneInstanceId);
    }

    /**
     * 查的场景实例
     *
     * @param sceneId
     * @param businessTypeId
     * @param businessKey
     */
    @Override
    public SceneInstance findSceneInstance(String sceneId, String businessTypeId, String businessKey) {
        return sceneInstanceService.findSceneInstance(sceneId, businessTypeId, businessKey);
    }

    /**
     * 查的场景实例
     *
     * @param scene
     * @param businessType
     * @param businessKey
     */
    @Override
    public SceneInstance findSceneInstance(Scene scene, BusinessType businessType, String businessKey) {
        return sceneInstanceService.findSceneInstance(scene, businessType, businessKey);
    }

    /**
     * 查的场景实例流
     *
     * @param sceneInstanceId
     * @param sceneFlowId
     */
    @Override
    public List<SceneInstanceFlow> findSceneInstanceFlow(String sceneInstanceId, String sceneFlowId) {
        return sceneInstanceService.findSceneInstanceFlow(sceneInstanceId, sceneFlowId);
    }

    /**
     * 查的场景实例流
     *
     * @param sceneInstance
     * @param sceneFlow
     */
    @Override
    public List<SceneInstanceFlow> findSceneInstanceFlow(SceneInstance sceneInstance, SceneFlow sceneFlow) {
        return sceneInstanceService.findSceneInstanceFlow(sceneInstance, sceneFlow);
    }

    /**
     * 创建场景实例流
     *
     * @param sceneInstance
     * @param sceneFlow
     */
    @Override
    public SceneInstanceFlow createSceneInstanceFlow(SceneInstance sceneInstance, SceneFlow sceneFlow) {
        return sceneInstanceService.createSceneInstanceFlow(sceneInstance, sceneFlow);
    }

    /**
     * 创建场景实例角色
     *
     * @param sceneInstance
     * @param businessTypeId
     * @param businessKey
     */
    @Override
    public SceneInstanceRole createSceneInstanceRole(SceneInstance sceneInstance, String businessTypeId, String businessKey) {
        return sceneInstanceService.createSceneInstanceRole(sceneInstance, businessTypeId, businessKey);
    }

    /**
     * 创建场景实例角色
     *
     * @param sceneInstance
     * @param businessType
     * @param businessKey
     */
    @Override
    public SceneInstanceRole createSceneInstanceRole(SceneInstance sceneInstance, BusinessType businessType, String businessKey) {
        return sceneInstanceService.createSceneInstanceRole(sceneInstance, businessType, businessKey);
    }
}
